package com.LensBlaster.upload.Flickr;



import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;

/**
 * Used to clear the Flickr authentication token, so that the user
 * can link to another Flickr account.
 * @author Michael
 *
 */
public class ClearLoginPreference extends Preference {
	View dialogView;

    /**
     * Construct the preference, using the context to retrieve preferences.
     */
    public ClearLoginPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        final Context localContext = context;
        this.setOnPreferenceClickListener(new OnPreferenceClickListener(){
        	
        	/**
        	 * Clear the entries in the SharedPreferences object associated with "lensblaster"
        	 */
//        	@Override
        	public boolean onPreferenceClick(Preference p){
        		
        		new AlertDialog.Builder(localContext)
        		.setMessage("Clear Flickr account info?")
        		.setPositiveButton("Confirm",
        			new DialogInterface.OnClickListener() {
        				public void onClick(DialogInterface dialog, int whichButton) {
        					dialog.dismiss();
        					android.util.Log.d("lens", "Clearing Flickr info.");
        	        		SharedPreferences sp =
        	        			localContext.getSharedPreferences(com.LensBlaster.upload.Flickr.Upload.PREFERENCES,0);
        	       		  	Editor ed = sp.edit();
        	       		  	ed.clear();
        	       		  	ed.commit();
        				}
        			})
        		.setCancelable(true)
        		.setNegativeButton("Cancel",
        						new DialogInterface.OnClickListener() {
        							public void onClick(DialogInterface dialog,
        									int which) {
        								dialog.dismiss();
        							}
        						})
        		.create()
        		.show();
       		  	
        		return true;
        	}
        });
    }
}

